clear
* Change directory to where the folder with the data is
cd "Data Archive TWT Predictions\KTHDP"

*Merge predictions from different utility and noise specifications
*ChoicePredictionFechnerCARAKTHDP also containst the TWT predictions
use ChoicePredictionFechnerCARAKTHDP, clear
merge 1:1 subj  using ChoicePredictionFechnerCRRAKTHDP, clear
merge 1:1 subj  using ChoicePredictionFechnerRPMCARAKTHDP, clear
merge 1:1 subj using ChoicePredictionFechnerRPMCRRAKTHDP, clear

*Summarize and tests the absolute error distance
sum dist  distCRRA  distCARA  distRPMCRRA  distRPMCARA 
signrank dist  = distCRRA
signrank dist  = distCARA
signrank dist  = distRPMCRRA
signrank dist  = distRPMCARA 

*Produce Figure 3 Right
preserve
gen G =_n
sum  dist, detail
gen graphEPV = r(mean)*100 if G==1
ci mean dist, level(95)
gen low = r(lb)   if G==1
gen high = r(ub)  if G==1
sum distCRRA , detail
replace graphEPV = r(mean)*100 if G==3
ci mean distCRRA, level(95)
replace low = r(lb)   if G==3
replace high = r(ub)  if G==3
sum distCARA, detail
replace graphEPV = r(mean)*100 if G==5
ci mean distCARA, level(95)
replace low = r(lb)   if G==5
replace high = r(ub)  if G==5
sum distRPMCRRA, detail
replace graphEPV = r(mean)*100 if G==7
ci mean distRPMCRRA, level(95)
replace low = r(lb)   if G==7
replace high = r(ub)  if G==7
sum distRPMCARA, detail
replace graphEPV = r(mean)*100 if G==9
ci mean distRPMCARA, level(95)
replace low = r(lb)   if G==9
replace high = r(ub)  if G==9
keep if G<10
replace low= low*100
replace high =high*100
#delimit ;
twoway 
(bar  graphEPV G if G ==1 ,lcolor(black)  fcolor(black)  )
(bar  graphEPV G if G ==3 ,lcolor(black)  fcolor(gs5)  )
(bar  graphEPV G if G ==5 ,lcolor(black)  fcolor(gs8)  )
(bar  graphEPV G if G ==7 ,lcolor(black)  fcolor(gs12)  )
(bar  graphEPV G if G ==9 ,lcolor(black)  fcolor(gs15)  )
(rcap high   low G, lcolor(red))
,
  graphregion(color(white) fcolor(white) lcolor(white)  ) plotregion(fcolor(white) lcolor(white) )
 ytitle("Mean Absolute Errors (%)" " ", size(large)) 
     ylabel(0(10)60, grid) title("KTHDP")
 xlabel(1 "TWT" 3"RUM-CRRA" 5"RUM-CARA" 7"RPM-CRRA" 9"RPM-CARA", noticks   )
xtitle("  ")
legend(off)  
 name(Figure3Right, replace) saving(Figure3Right, replace)
;#delimit cr
graph export Figure3Right.eps, as(eps) preview(on) replace
restore
